SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[DISC_DistOrderItemsUpdate]
	@ID int,  
	@DownloadLink varchar(max),  
	@GenerationStatus varchar(20),  
	@GenerationError nvarchar(255),
	@MaxDownloads int = -1,
	@Promo nvarchar(255) = null,
	@UsersID nvarchar(255) = null,
	@StampVars nvarchar(max) = null,
	@Password nvarchar(255) = null,
	@FileName nvarchar(255) = null
AS
BEGIN
	UPDATE [DISC_DistOrderItems]  
	SET   
	 DownloadLink = @DownloadLink,  
	 GenerationStatus = @GenerationStatus,  
	 GenerationError = @GenerationError,
	 MaxDownloads = case when @MaxDownloads >= 0 then @MaxDownloads else MaxDownloads end,
	 Promo = coalesce(@Promo, Promo),
	 UsersID = coalesce(@UsersID, UsersID),
	 StampVars = coalesce(@StampVars, StampVars),
	 Password = coalesce(@Password, Password),
	 FileName = coalesce(@FileName, FileName)
	WHERE [ID] = @ID  

END
GO
